package cn.xy.log;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;

/**
 *  注解实现Aop
 */
@Aspect
public class AnnotationLog {

    //前置通知
    @Before("execution(* cn.xy.service.UserServiceImpl.*(..))")
    private void before(){
        System.out.println("方法执行前");
    }

    //后置通知
    @After("execution(* cn.xy.service.UserServiceImpl.*(..))")
    private void after(){
        System.out.println("方法执行后");
    }

    //环绕通知
    @Around("execution(* cn.xy.service.UserServiceImpl.*(..))")
    public void around(ProceedingJoinPoint jp) throws Throwable {
        System.out.println("环绕前");
        //执行方法，（否则就不执行方法）
        Object proceed = jp.proceed();
        System.out.println("环绕后");
    }

}
